package homework08;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

interface IntergerStack {
	public Integer push(Integer item); 
	public Integer pop();                      
	public Integer peek();                  
	public boolean empty();               
	public int size();                            
}
class ArrayListIntegerStack implements IntergerStack{
	
	private List<Integer> arrList = new ArrayList<Integer>();
	
	@Override
	public Integer push(Integer item) {
		// TODO Auto-generated method stub
		if(item==null)
			return null;

		else arrList.add(item);
		
		return null;
	}

	@Override
	public Integer pop() {
		// TODO Auto-generated method stub
		if(arrList.isEmpty())
			return null;
		else arrList.remove(arrList.size()-1);
		return null;
	}

	@Override
	public Integer peek() {
		// TODO Auto-generated method stub
		if(arrList.isEmpty())		
			return null;
	
		else return arrList.get(arrList.size()-1);
	}

	@Override
	public boolean empty() {
		// TODO Auto-generated method stub
		if(arrList.isEmpty())		
			return true;
		
		else return false;
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return arrList.size();
	}

	@Override
	public String toString() {
		return arrList.toString();
	}
	
	
	
	
	
}
public class Seven01 {
	public static void main(String[] args){
		ArrayListIntegerStack arr = new ArrayListIntegerStack();
		Scanner sc = new Scanner(System.in);
		int m=sc.nextInt();
		for(int i=0;i<m;i++)
		{
			arr.push(Integer.valueOf(sc.nextInt()));
			System.out.println(arr.peek());
		}
		System.out.println(arr.peek()+","+arr.empty()+","+arr.size());
		System.out.println(arr.toString());
		int x=sc.nextInt();
		for(int i=0;i<x;i++)
		{
			System.out.println(arr.peek());
			arr.pop();
		}
		System.out.println(arr.peek()+","+arr.empty()+","+arr.size());

		System.out.println(arr.toString());
		
		
		sc.close();
	}
}
